window.onload=function () {


var vue=new Vue({
        el:"#axios",
        data:{
            msg:"学习axios,发出请求",
            gets:"",
            posts: "",
            /*用来接收后台传来的数据集合*/
            list:[],//先让数组变为空
            search: "搜索",

        },
        methods:{
            get:function () {
                var that=this;//that 用来接收this，成为转换的媒介-

                axios.get("/get").then(function(response){
                    that.gets=response.data
                },function(erro){
                    console.log("错误")

                })
            },
            post:function(){
                /*请求的接口*/
                var that=this;
                axios.post("/post").then(function(response){
                    console.log(response.data.data)
                    that.posts=response.data.data
                },function(erro){
                    console.log("错误")

                })
            },
  /*          enter:function () {  和enter (){} 一样的*/
            enter:function () {
                var that=this;
                //用来接收转换
                if(this.search==""){ //空的话，查全部
                    axios.post("/selall?index=1&limit=3").then(function (response) {
                        console.log(response.data);

                        that.list=response.data.data;


                    }).catch(function (erro) {
                        console.log("出错了")

                    })
                }else{//不是空按名字查找
                    axios.post("/selall/"+this.search).then(function (response) {
                        console.log(response.data);
                        that.list=response.data.data;
                    }).catch(function (erro) {
                        console.log("出错了")

                    })
                }


            },
            cli  () {
                var that=this;
                //用来接收转换

                if(this.search==""){ //空的话，查全部
                    axios.post("/selall?index=1&limit=3").then(function (response) {
                        console.log(response.data.data);
                        that.list=response.data.data;
                    }).catch(function (erro) {
                        console.log("出错了")

                    })
                }else{
                    axios.post("/selall/"+this.search).then(function (response) {
                        console.log(response.data);
                        that.list=response.data.data;
                    }).catch(function (erro) {
                        console.log("出错了")

                    })
                }

            }


        }
    })
}